package com.finalist.dao.impl;


import javax.persistence.FlushModeType;

import org.springframework.stereotype.Repository;

import com.finalist.dao.DepartureDao;
import com.finalist.entity.Departure;

@Repository("departureDaoImpl")
public class DepartureDaoImpl extends BaseDaoImpl<Departure, Long> implements DepartureDao{

	   @Override
	    public boolean nameExists(String name)
	    {
	        if (name == null)
	        {
	            return false;
	        }
	        String jpql = "select count(*) from Departure de where lower(de.name) = lower(:name)";
			Long count = entityManager.createQuery(jpql, Long.class).setFlushMode(FlushModeType.COMMIT).setParameter("name", name).getSingleResult();
			return count > 0;
	    }
}
